WindowViewBase.cs
Language: C#
Last Modified: 2020-06-27 1:58:34 PM UTC
File Size: 4629 bytes
Last Modified: 2020-06-27 1:58:34 PM UTC
File Size: 4629 bytes
http://www.penguinstew.ca/example/MVVMbase/ViewBase/WindowViewBase.cs
���usingSystem;
usingSystemWindows;
usingPenguinMVVMBaseViewModelBase;
namespacePenguinMVVMBaseViewBase
{
<summary>
ThebaseclassforWindowviews
<summary>
publicabstractclassWindowViewBase:Window
{
regionVariables
<summary>
ViewModelforthisview
<summary>
protectedIWindowViewModelm_viewModel;
endregion
regionConstructor
<summary>
Parameterlessconstructorfordesignview
<summary>
publicWindowViewBase:thisnewWindowViewModelBase{}
<summary>
BaseconstructortakesviewModelasanargumentandsetsupeventhandlers
<summary>
<paramname=viewModel>TheviewModelforthisview<param>
publicWindowViewBaseIWindowViewModelviewModel
{
m_viewModel=viewModel;
thisDataContext=m_viewModel;
Setupeventhandlers
m_viewModelViewRequested=m_viewModel_ViewRequested;
m_viewModelMsgBoxRequested=m_viewModel_MsgBoxRequested;
thisLoaded=View_Loaded;
}
endregion
regionEventHandlers
<summary>
EventhandlerfortheLoadedevent
<summary>
privatevoidView_LoadedobjectsenderRoutedEventArgse
{
Calltheloadedmethodontheviewmodeltodealwiththeviewbeingloaded
m_viewModelViewLoadedsendere;
return;
}
<summary>
EventhandlerforViewRequestedoverwrittenforviewstohandlespecificviewModels
<summary>
<paramname=sender>TheviewModelrequestingtheview<param>
<paramname=e>RequestViewArgscontainingtheViewModeltouse<param>
protectedvirtualvoidm_viewModel_ViewRequestedobjectsenderRequestViewArgse
{
Defaultimplementationdonothing
return;
}
<summary>
EventhandlerforMsgBoxRequestedcreatesaMessageBoxwithgivenparameters
<summary>
<paramname=sender>TheviewModelrequestingtheview<param>
<paramname=e>RequestMsgBoxArgscontainingtheMessageBoxoptions<param>
protectedvoidm_viewModel_MsgBoxRequestedobjectsenderRequestMsgBoxArgse
{
MessageBoxResultresult=MessageBoxShoweMessageBoxTexteMessageBoxCaption
eMessageBoxButtonseMessageBoxIcon;
ifeCallback=null
{
eCallbackresult;
}
}
<summary>
HandlestheClosedeventoftherequestedwindowview
InformstherequestingviewModeloftheclosure
<summary>
<paramname=sender>Therequestedviewwindow<param>
<paramname=e>EventArgs<param>
privatevoidView_ClosedobjectsenderEventArgse
{
WindowViewBaseview=senderasWindowViewBase;
ifview=null
{
Calltherequestedviewclosedmethodreturnisalwaysfalseforwindows
m_viewModelRequestedViewClosedIWindowViewModelviewDataContextfalse;
}
}
endregion
regionProtectedMethods
<summary>
Opensthegivenview
<summary>
<paramname=view><param>
protectedvoidOpenViewWindowViewBaseview
{
viewOwner=this;
ifviewisDialogViewBase
{
IfviewisbasedonDialogbaseopenitwithShowDialog
bool?result=viewShowDialog;
Callrequestedviewclosedwiththeresultorfalseifnovalue
ifresultHasValue
{
m_viewModelRequestedViewClosedIWindowViewModelviewDataContextresultValue;
}
else
{
m_viewModelRequestedViewClosedIWindowViewModelviewDataContextfalse;
}
}
else
{
Elseassumeitsawindowandopenitwithshow
viewClosed=View_Closed;
viewShow;
}
}
endregion
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134